/*
 * This file is part of the <a href="http://code.google.com/p/pux">PUX Framework</a>
 *
 * Copyright 2008 by <a href="mailto:jfendler@polytechnic.edu.na">Jens Fendler</a>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package de.teamskill.pux.samples.image;

import java.io.File;
import java.util.logging.ConsoleHandler;
import java.util.logging.Handler;
import java.util.logging.Level;

import de.teamskill.pux.engine.Logging;
import de.teamskill.pux.engine.Network;
import de.teamskill.pux.engine.AbstractNode;
import de.teamskill.pux.library.gui.ImageDisplayNode;
import de.teamskill.pux.library.image.ImageLoaderNode;
import de.teamskill.pux.library.image.TextOverlayNode;
import de.teamskill.pux.library.math.RandomNumberNode;

/**
 * ImageDetailsTest prints out the dimensions and number of pixels for a given
 * image
 * 
 * @author <a href="mailto:jfendler@polytechnic.edu.na">Jens Fendler</a>
 * 
 */
public class ImageDetailsTest implements Logging {

	/**
	 * net
	 */
	private Network net;

	/**
	 * ImageDetailsTest Constructor
	 * 
	 */
	public ImageDetailsTest() {
		Handler h = new ConsoleHandler();
		h.setFilter(null);
		h.setLevel(Level.ALL);
		LOG_NET.addHandler(h);
		LOG_NODE.addHandler(h);
		LOG_PORT.addHandler(h);

		setup();
		start();
	}

	/**
	 * setup
	 * 
	 */
	private void setup() {
		net = new Network();
		String imageFile = null;
		try {
			imageFile = new File("/home/jf/test.jpg").getCanonicalPath();
		} catch (Exception e) {
			e.printStackTrace(System.err);
			System.exit(1);
		}

		AbstractNode image = new ImageLoaderNode().addToNetwork(net).makeStartupNode();
		image.configure(ImageLoaderNode.CONFIG_IMAGEURI, imageFile);

		AbstractNode display = new ImageDisplayNode("Image", false).addToNetwork(net);
		AbstractNode random = new RandomNumberNode("Random", 1, false).addToNetwork(net).makeStartupNode();
		AbstractNode overlay = new TextOverlayNode("Overlay", false).addToNetwork(net);

		net.connect(image.getOutputPort("BUFFEREDIMAGE"), overlay.getInputPort("IN"));
		net.connect(random.getOutputPort("OUT1"), overlay.getInputPort(TextOverlayNode.IN_TEXT));
		net.connect(overlay.getOutputPort("OUT"), display.getInputPort("IN"));

	}

	/**
	 * start
	 * 
	 */
	private void start() {
		net.start();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new ImageDetailsTest();
	}

}
